<template>
  <div>
    <el-card class="main">
      <div class="header">
        <div class="title-text">评价数据</div>
        <!-- <el-select v-model="value.item" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select> -->
      </div>

      <div class="center"  >
        <div class="item">
          <div class="tex">询问数量</div>
          <div class="quantity">
            <span>{{ questionCount?questionCount:0 }}</span>
            <!-- <div>
              评率：
              <span>120</span>
            </div> -->
          </div>
        </div>
        <div class="item">
          <div class="tex">评价数量</div>
          <div class="quantity">
            <span>{{ center[0]+center[1]+center[2]+center[3]+center[4] }}</span>
          </div>
        </div>
        <div class="item">
          <div class="tex">非常满意&满意</div>
          <div class="quantity">
            <span>{{ center[3]+center[4] }}</span>
            <div>
              评率：
              <span>{{center[3]+center[4]==0?0:parseInt(((center[3]+center[4])/(center[0]+center[1]+center[2]+center[3]+center[4]))*100)}}%</span>
            </div>
          </div>
        </div>
        <div class="item">
          <div class="tex">一般</div>
          <div class="quantity">
            <span>{{ center[2] }}</span>
            <div>
              评率：
              <span>{{center[2]==0?0:parseInt(((center[2])/(center[0]+center[1]+center[2]+center[3]+center[4]))*100)}}%</span>
            </div>
          </div>
        </div>
        <div class="item">
          <div class="tex">不满意&非常不满意</div>
          <div class="quantity">
            <span >{{center[0]+center[1]  }}</span>
            <div>
              评率：
              <span>{{center[0]+center[1]==0?0:parseInt(((center[0]+center[1])/(center[0]+center[1]+center[2]+center[3]+center[4]))*100)}}%</span>
            </div>
          </div>
        </div>
      </div>
    </el-card>
    <el-card class="main index">
      <div class="search">
        <div class="isdate">
          <span> 评价时间 </span>
          <el-select v-model="value.date" placeholder="请选择">
            <el-option
              v-for="item in date"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div>
          <span> 评价类型 </span>
          <el-select v-model="value.type" placeholder="请选择">
            <el-option
              v-for="item in type"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div class="useritem">
          <span> 用户昵称 </span>
          <el-input v-model="name" placeholder="请输入内容"></el-input>
        </div>
        <div>
          <el-button>重置</el-button>
          <el-button @click="getCustomerEvaluateRecordByPage()" type="primary">查询</el-button>
        </div>
      </div>
      <div>
        <el-table :data="lists">
        <el-table-column
          property="evaluateTime"
          label="日期"
          width="300"
        ></el-table-column>
        <el-table-column
          property="userName"
          label="姓名"
          width="400"
        ></el-table-column>
        <el-table-column  label="评价"> 

          <template slot-scope="{ row, $index }">
            <p v-if="row. evaluateType == 1">非常不满意</p>
            <p v-else-if="row.evaluateType == 2">不满意</p>
            <p v-else-if="row.evaluateType==3">一般</p>
            <p v-else-if="row.evaluateType==4">满意</p>
            <p v-else-if="row.evaluateType==5">非常满意</p>
            
          </template>
        </el-table-column>
      </el-table>
      </div>

      <!-- 分页 -->
    <el-pagination style="margin-top:20px;text-align:center" @size-change="handleSizeChange"
      @current-change="handleCurrentChange" :current-page="pageNumber" :page-sizes="[10, 50, 100]" :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper" :total="total">
    </el-pagination>
    </el-card>
   
  </div>
</template>

<script>
import { forEach } from 'jszip';

export default {
  name: "setup",

  data() {
    return {
      questionCount:0,
      list:[1,2,3,4,5],
      center:[0,0,0,0,0],
       //页码
       pageNumber: 1,
      //每页数量
      pageSize: 10,
      //总条数
      total: 0,
      name: "",
      lists: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
      ],
      userName: "",
      activeName: "first",
      date: [
        {
          label: "全部",
        },
        {
          value: 1,
          label: "今日",
        },
        {
          value: 2,
          label: "近一周",
        },
        {
          value: 3,
          label: "近一个月",
        },
        {
          value: 4,
          label: "近三个月",
        },
      ],
      type: [
        {
          label: "全部",
        },
        {
          value: 1,
          label: "非常不满意",
        },
        {
          value: 2,
          label: "不满意",
        },
        {
          value: 3,
          label: "一般",
        },
        {
          value: 4,
          label: "满意",
        },
        {
          value: 5,
          label: "非常满意",
        },
      ],
      options: [
        {
          value: "选项1",
          label: "不满意",
        },
        {
          value: "选项2",
          label: "非常不满意",
        },
      ],
      value: {},
      Record:''
    };
  },

  computed: {},
  mounted() {
    this.getCustomerEvaluateRecord();
    this.getCustomerEvaluateRecordByPage()
  },

  methods: {
    async getCustomerEvaluateRecordByPage() {
      
      let res = await this.$API.kefu.getCustomerEvaluateRecordByPage({
        customerId: Number(localStorage.getItem("id")),
        page: this.pageNumber,
        size: this.pageSize,
        evaluateTime: this.value.date,
        evaluateType: this.value.type,
        userName: this.userName,
      });
      console.log(res,'临沭县');
      if (res.code == 200) {
        this.lists = res.data.rows;
        this.total=res.data.sumLine
      } else {
        this.$message("加载失败");
      }
    },
    async getCustomerEvaluateRecord() {
      console.log(localStorage.getItem("id"));
      let res = await this.$API.kefu.getCustomerEvaluateRecord({
        customerId: localStorage.getItem("id"),
        // "customerId":"2275"
      });
      
      this.questionCount=res.data.questionCount
      if(res.code==200){
         res.data.level.forEach((item,index) => {
         this.list.forEach((item1,index1)=>{
          if(item1==item){
            this.center[index1]=res.data.count[index]
          }
         })
      })
      console.log(this.center,'center');
      }
       
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.getCustomerEvaluateRecordByPage();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.pageNumber = val;
      this.getCustomerEvaluateRecordByPage();
    }
  },
};
</script>

<style lang="scss" scoped>
.useritem{
  display: flex;
  align-items: center;
  span{
    // 不换行
    margin-right: 3px;
    white-space: nowrap;
  }
}
.main {
  margin: 17px;
  .center {
    margin-top: 10px;
    display: flex;
    justify-content: space-evenly;
    .item {
      width: 238px;
      height: 102px;
      padding: 16px;
      //   margin-top: ;
      background: #f6f6f6;
      border-radius: 10px 10px 10px 10px;
      .tex {
        color: #999999;
        font-size: 14px;
      }
      .quantity {
        height: 65px;
        display: flex;
        justify-content: space-between;
      }
      span {
        font-size: 26px;
        line-height: 2;
        font-weight: 700;
        color: #3d3d3d;
      }
    }
  }
  .title-text {
    line-height: 1;
    font-size: 18px;
  }
  ::v-deep .el-card__body {
    width: 100%;
    height: 100%;

    .header {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 1000%;
    }
  }
}
.index {
//   ::v-deep .el-card__body {
//     display: flex;
//     justify-content: space-between;
//   }
.search{
    display: flex;
    justify-content: space-between;
}
}
</style>